package com.springsecurity.controller;

import com.springsecurity.comment.R;
import com.springsecurity.constants.MessageConstant;
import com.springsecurity.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <h3>Spring-Security</h3>
 * <p>登陆</p>
 *
 * @author gdw
 * @since 2024-07-12 09:49:29
 */
@RestController
public class UserController {
    @Autowired
    private UserService service;
    @Autowired
    private HttpMessageConverters messageConverters;

    /**
     * 登陆
     * @param
     * @return
     */
    @PostMapping("/user/login")
    public R login(@RequestBody Map<String,Object> map) {
        //验证参数
        if(map.get("userName")==null ||"".equals(map.get("userName"))){
            return R.error(MessageConstant.NOT_USER_USERNAME);
        }else if(map.get("password")==null ||"".equals(map.get("password"))){
            return R.error(MessageConstant.NOT_USER_PASSWORD);
        }
        return service.login(map);
    }

}

